package org.qq.serverthread;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.net.URISyntaxException;
import java.util.ArrayList;

import org.qq.ui.ServerJframe;
import org.qq.util.UserSaveFile;
import org.qq.util.Util;
import org.qq.util.userReadFile;

/**
 * 
 * project_name:QQ
 * package_name:org.qq.thread
 * file_name:RegistUserThread.java
 * @author Link
 * create_date:2015年8月28日下午11:38:12
 * modified_date:
 * description: 存储用户信息线程
 *
 */
public class SerRegistReply{
	
	private String registstr;					//用户注册字符串
	private ArrayList<String> userInformation;	//用户注册信息集合
	private Socket s;							//连接的套接字
	private String reply;						//返回client端的信息
	private PrintStream ps;						//输出流
	private File file;
	
	
	public SerRegistReply() {
		super();
	}

	public SerRegistReply(String registstr,Socket s) {
		super();
		this.registstr = registstr;
		this.s = s;
		try {
			ps = new PrintStream(s.getOutputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public String getRegiststr() {
		return registstr;
	}

	public void setRegiststr(String registstr) {
		this.registstr = registstr;
	}
	
	/**
	 * 
	 * description: 发消息到注册用户端
	 * 2015年8月31日 下午2:50:49
	 * @author Link
	 * void
	 *
	 */
	public synchronized void sendMessageToResClient(){
		try {
			file = new File(SerRegistReply.class.getResource("/file/用户注册信息.txt").toURI());
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}
		userInformation = new ArrayList<String>();
		userInformation = new userReadFile(file).readFile();//调用读取用户信息类将用户信息存储到集合userInformation中
		if(Util.judgeRegistMethod(userInformation, registstr)){//调用Util包里判断账号是否存在方法,如果为true表示账号已经存在
			reply = "false----regist";
		}else{//
			new UserSaveFile().registUserSave(registstr);//不存在时调用存储方法
			reply = "true----regist";
		}
		ps.println(reply);
	}
}






